package com.seuic.posdsdk.device_interface;

import android.os.Bundle;


public interface PinpadDevice extends BaseInterface {
    /**
     * Download the protect key used to encrypt main key
     *
     * @param index The key index
     * @param protectKey The protect key, not encrypted
     * @return 0 when download success, or other when failed
     */
    int downloadProtetKey(int index, String protectKey);

    /**
     * Download encrypted main key
     *
     * @param index The key index
     * @param mainKey Main key, encrypted by protect key
     * @param checkValue Checkvalue of main key
     * @return 0 when download success, or other when failed
     */
    int downloadMainkey(int index, String mainKey, String checkValue);

    /**
     * Download work keys used in transactions
     * All the workkeys should be encrypted by mainkey
     *
     * @param index The key index
     * @param pinKey Encrypted pin key, used to encrypt pin
     * @param pinKeyCheckValue  Pin key checkvalue
     * @param macKey Encrypted mac key, used to calculate mac
     * @param macKeyCheckValue Mac key checkvalue
     * @param tdKey Encrypted track key, used to encrypt magcard tracks
     * @param tdKeyCheckValue  Track key checkvalue
     * @return 0 when download success, or other when failed
     */
    int downloadWorkKeys(int index, String pinKey, String pinKeyCheckValue,
                         String macKey, String macKeyCheckValue,
                         String tdKey, String tdKeyCheckValue);

    /**
     * Use mac key to do encryption
     *
     * @param index The key index
     * @param msg The Msg to encrypt, the length should be the multiple of 16
     * @return The encrypt result, or null when failed
     */
    String macKeyEncrypt(int index, String msg);

    /**
     * Use mac key to do decryption
     *
     * @param index The key index
     * @param msg The Msg to decrypt, the length should be the multiple of 16
     * @return The encrypt result, or null when failed
     */
    String macKeyDecrypt(int index, String msg);

    /**
     * Use track key to do encryption
     *
     * @param index The key index
     * @param msg The Msg to encrypt, the length should be the multiple of 16
     * @return The encrypt result, or null when failed
     */
    String trackKeyEncrypt(int index, String msg);

    /**
     * Use track key to do decryption
     *
     * @param index The key index
     * @param msg The Msg to decrypt, the length should be the multiple of 16
     * @return The encrypt result, or null when failed
     */
    String trackKeyDecrypt(int index, String msg);

    /**
     * Get Tusn Data
     * For transactions in China only, not used in overseas
     *
     * @param random Random number
     * @return TUSN Data, or null when failed
     */
    Bundle getTusn(String random);

    /**
     * Start enter pin function
     * When Called, the enter pin process will be started
     * The events and result of the process will be returned in callbacks
     * @see EnterPinCallback for callback events
     *
     * @param enterPinCallback The callbacks in enter pin process
     * @param param the bundle of enter pin input parameters
     *              @see com.seuic.constants.PinpadConstants
     *              PINKEY_INDEX(int), the key index to encrypt pin
     *              AMOUNT(int), the amount of transaction
     *              PAN(String), the primary account number of the card
     *              PIN_LENGTH_LIMITS( int[] ), the pin length supported,
     *                  for example { 0, 4, 6 } stand for the pinpad support pin length 0, 4 and 6
     */
    void enterPin(EnterPinCallback enterPinCallback, Bundle param);

    /**
     * The enter pin event callbacks
     */
    interface EnterPinCallback {
        /**
         * Enter pin process finished successfully
         *
         * @param enc The encrypted pin
         * @param is_no_pin whether the custom has not enter pin and just press OK
         */
        void onSuccess(String enc, boolean is_no_pin);

        /**
         * Enter pin process failed
         *
         * @param error The error description
         */
        void onFail(String error);

        /**
         * The key pressed event
         * will not called in terminals with touchscreen only (not equiped with a pinpad)
         *
         * @param input_num Current number of pins already entered
         *                  used to dislay an animation like ******
         */
        void onInput(int input_num);
    }
}
